<?php 
header("Content-type:text/html;charset=utf-8");
$rand = mt_rand(1000.9999);
$apikey = "d230f5ee23569c5afd169e926b8ec6e1";//修改为你的apikey(http://www.yupian.com)登录官网后获取
$mobile = "18748342258";//请用自己的手机号码,你要发送的手机号码
$text = "【云片网】您的验证码是2345";//发送内容
$ch = curl_init();

//设置验证方式
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Accept:text/plain;charset=utf-8','Content-Type:application/x-www-form-urlencoded','charset=utf-8'));
//设置返回结果为流
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//设置超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,10);
//设置通讯方式
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
//取得用户信息
$json_data = get_user($ch,$apikey);
$array = json_decode($json_data,true);
echo '<pre>';
print_r($array);
$data = array('text'=>$text,'apikey'=>$apikey,'mobile'=>$mobile);
$json_data = send($ch,$data);
$array = json_decode($json_data,true);
echo '<pre>';
print_r($array);


curl_close($ch);

//获得账户
function get_user($ch,$apikey){
	curl_setopt($ch,CURLOPT_URL,'https://sms.yunpian.com/v1/user/get.json');
	curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(array('apikey'=>$apikey)));
	return curl_exec($ch);
}

function send($ch,$data){
	curl_setopt($ch,CURLOPT_URL,'https://sms.yunpian.com/v1/sms/send.json');
	curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));
	return curl_exec($ch);
}
